package com.weishi.project.training.controller;

import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.framework.web.page.TableDataInfo;
import com.weishi.project.training.domain.HeartRate;
import com.weishi.project.training.service.IHeartRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 心率Controller
 */
@RestController
@RequestMapping("/training/heartRate")
public class HeartRateController extends BaseController {

    /**
     * 心率表 接口
     */
    @Autowired
    private IHeartRateService heartRateService;

    /**
     * 查询心率列表
     */
    //@PreAuthorize("@ss.hasPermi('training:rate:list')")
    @GetMapping("/list")
    public TableDataInfo list(HeartRate heartRate) {
        startPage();
        List<HeartRate> list = heartRateService.selectHeartRateList(heartRate);
        return getDataTable(list);
    }

    /**
     * 导出心率列表
     */
    //@PreAuthorize("@ss.hasPermi('training:rate:export')")
    @Log(title = "心率", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HeartRate heartRate) {
        List<HeartRate> list = heartRateService.selectHeartRateList(heartRate);
        ExcelUtil<HeartRate> util = new ExcelUtil<HeartRate>(HeartRate.class);
        return util.exportExcel(list, "rate");
    }

    /**
     * 获取心率详细信息
     */
    //@PreAuthorize("@ss.hasPermi('training:rate:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(heartRateService.getById(id));
    }

    /**
     * 新增心率
     */
    @PostMapping
    public AjaxResult add(@RequestBody HeartRate heartRate) {
        heartRateService.save(heartRate);
        return AjaxResult.success();
    }

    /**
     * 修改心率
     */
    @Log(title = "心率", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeartRate heartRate) {
        heartRateService.updateById(heartRate);
        return AjaxResult.success();
    }

    /**
     * 删除心率
     */
    @Log(title = "心率", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        heartRateService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
    
}